package com.example.hadoop.mapreduce.flowcount;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Brian
 * @Date: 2020/04/22/20:34
 * @Description:
 */
@Data
@NoArgsConstructor
public class FlowBean implements Writable {

    private long upFlow;
    private long dFlow;
    private long totalFlow;

    public FlowBean(long upFlow, long dFlow) {
        this.upFlow = upFlow;
        this.dFlow = dFlow;
        this.totalFlow = upFlow + dFlow;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);
        out.writeLong(dFlow);
        out.writeLong(totalFlow);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        upFlow = in.readLong();
        dFlow = in.readLong();
        totalFlow = in.readLong();
    }

    public String toString() {
        return "上行流量：" + upFlow + "\t下行流量：" + dFlow + "\t总流量：" + totalFlow;
    }
}
